# #!/bin/bash

# # 设置CAN接口
# ip link set can0 down
# ip link set can0 type can bitrate 1000000 triple-sampling on
# ip link set can0 up

# # 开始监听CAN总线
# candump can0 &
# candump_pid=$!

# # 接收和回复CAN消息
# while read -r line; do
#     message="${line#*#}"
#     # message="${message// /}"
#     # message="${message%$'\r'}"
#     # echo "Received message: $message"

#     reply="${message}"
#     cansend can0 "${reply}"
#     echo "Sent reply: $reply"
# done

# # 结束监听CAN总线
# kill $candump_pid

# echo "CAN bus listener begin execution"

#!/bin/bash

# 设置CAN接口
ip link set can0 down
ip link set can0 type can bitrate 1000000 triple-sampling on
ip link set can0 up

# 开始监听CAN总线，并将输出重定向到脚本中
exec candump can0 | while read -r line; do
    message="${line#*#}"
    message="${message// /}"
    message="${message%$'\r'}"
    echo "Received message: $message"

    if [ "$message" = "can0001[8]0000000000000000" ]; then
        reply="5A1#1122.3344.5566.7788"
        cansend can0 "${reply}"
        echo "Sent reply: $reply"
    fi

done

echo "CAN bus listener begin execution"



